package com.mdb.open.common.enums.trade.status;

import com.google.common.collect.Lists;
import com.mdb.bc.api.enums.ApiEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 贸易融资申请订单状态
 * @author: you.yichao
 * @create: 2019-06-20 17:17
 **/
public enum LoanApplyOrderStatusEnum implements ApiEnum<String> {
    NOT_INITIATED("未发起"){
        @Override
        public List<LoanApplyWebStatusEnum> getWebGroup() {
            return Lists.newArrayList(LoanApplyWebStatusEnum.APPLY_APPLYING,
                                      LoanApplyWebStatusEnum.APPLY_NOT_INITIATED );
        }
    },
    UNDER_REVIEW( "审批中"){
        @Override
        public List<LoanApplyWebStatusEnum> getWebGroup() {
            return Lists.newArrayList(LoanApplyWebStatusEnum.APPLY_APPLYING,
                                      LoanApplyWebStatusEnum.APPLY_UNDER_REVIEW );
        }
    },
    SUCCESS("审核通过"){
        @Override
        public List<LoanApplyWebStatusEnum> getWebGroup() {
            return Lists.newArrayList(LoanApplyWebStatusEnum.APPLY_SUCCESS);
        }
    },
    REJECT("审批拒绝"){
        @Override
        public List<LoanApplyWebStatusEnum> getWebGroup() {
            return Lists.newArrayList(LoanApplyWebStatusEnum.APPLY_REJECT);
        }
    },
    /**
     * 目前仅考虑在开放平台看到
     */
    DEPOSIT_IN_ADVANCE("提前回货款或定金"){
        @Override
        public List<LoanApplyWebStatusEnum> getWebGroup() {
            return Lists.newArrayList(LoanApplyWebStatusEnum.APPLY_REJECT);
        }
    }
    ;

    //枚举描述
    private String text;

    /**
     * 分组函数 （仅用于【开放平台前端状态用】）
     */
    public abstract List<LoanApplyWebStatusEnum> getWebGroup();

    LoanApplyOrderStatusEnum(String text) {
        this.text = text;
    }

    @Override
    public String getValue() {
        return name();
    }

    @Override
    public String getText() {
        return this.text;
    }

    /**
     * 获取【开放平台】后端对应的状态值
     *  例：（前端）申请中 ：（后端）未发起、审批中
     */
    public static List<LoanApplyOrderStatusEnum> findWebBackendStatus(LoanApplyWebStatusEnum group) {
        List<LoanApplyOrderStatusEnum> list = new ArrayList<>();
        for (LoanApplyOrderStatusEnum fileType : LoanApplyOrderStatusEnum.values()) {
            if (fileType.getWebGroup().contains(group)) {
                list.add(fileType);
            }
        }
        return list;
    }
}
